package com.suning.sawp.service.impl.report;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.suning.sawp.constants.CacheKeyConstants;
import com.suning.sawp.constants.ClerkConstants;
import com.suning.sawp.constants.ConfigConstants;
import com.suning.sawp.constants.LoggerConstants;
import com.suning.sawp.dto.bi.OmsOrderItemPos;
import com.suning.sawp.dto.bi.StoreManDevMemberData;
import com.suning.sawp.dto.bi.StoreManRealIncSum;
import com.suning.sawp.dto.bi.StoreManRealIncomeDetail;
import com.suning.sawp.dto.bi.StoreManRealIncomeList;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.customer.CustshopFrequency;
import com.suning.sawp.dto.esb.AccountAlias;
import com.suning.sawp.dto.esb.CustSocietyInfoStruct;
import com.suning.sawp.dto.esb.QuerySocialityInfoResp;
import com.suning.sawp.dto.promotion.Promotion;
import com.suning.sawp.dto.promotion.PromotionDetail;
import com.suning.sawp.dto.promotion.PromotionSrc;
import com.suning.sawp.intf.bi.BiDataDaoService;
import com.suning.sawp.intf.esb.MemberInfoService;
import com.suning.sawp.intf.esb.ShopFrequencyService;
import com.suning.sawp.intf.report.ReportService;
import com.suning.sawp.po.bi.BiStoreRealIncDetailMEntity;
import com.suning.sawp.po.bi.StoreManDevMemberDetail;
import com.suning.sawp.po.bi.StoreManTotalDevMember;
import com.suning.sawp.service.util.AESUtils;
import com.suning.sawp.service.util.ConfigUtil;
import com.suning.sawp.service.util.DJStringUtils;
import com.suning.sawp.service.util.DateUtils;
import com.suning.sawp.service.util.RedisCacheUtils;
import com.suning.vgs.follow.remote.intf.StoreManRemoteService;
import com.suning.vgs.follow.remote.store.ClerkCustomerDevDataDto;
import com.suning.vgs.follow.remote.store.ClerkCustomerDevRetDto;

/**
 * 统计查询实现类
 * 
 * @author 14062606
 *
 */
@Service
public class ReportServiceImpl implements ReportService {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstants.SAWP_SERVICE);

    /**
     * 扫码注册
     */
    private static final String SCAN_REG = "1";
    /**
     * 代客注册
     */
    private static final String VALET_REG = "2";
    /**
     * 一键注册
     */
    private static final String DJ_APP_REG = "3";

    @Resource
    BiDataDaoService biDataDaoService;

    @Resource
    ShopFrequencyService shopFrequencyService;

    /**
     * follow 保存用户发展用户信息接口
     */
    @Resource
    StoreManRemoteService storeManRemoteService;

    @Autowired
    RedisCacheUtils cacheUtils;

    @Resource
    MemberInfoService memberInfoService;

    @Override
    public PromotionDetail queryPromotionList(int currIndex, int pageSize, String promoteDate, String promotionSrc,
            String staffId) {

        PromotionDetail promotionDetail = new PromotionDetail();
        List<PromotionSrc> promotionSrcList = new ArrayList<PromotionSrc>();

        Object[] args = { currIndex, pageSize, promoteDate, promotionSrc, staffId };
        LOGGER.error("查询会员发展明细，currIndex:{}, pageSize:{}, promoteDate:{}, " + "promotionSrc:{}, staffId:{}", args);

        List<ClerkCustomerDevRetDto> clerkCustomerList = storeManRemoteService.queryClerkCustomerDevPage(staffId,
                pageSize, currIndex, promoteDate, promotionSrc);

        // 会员编码列表
        List<String> custList = new ArrayList<String>();
        Map<String, String> custMobile = new HashMap<String, String>();

        List<Promotion> promotionList = new ArrayList<Promotion>();
        if (CollectionUtils.isNotEmpty(clerkCustomerList)) {
            for (ClerkCustomerDevRetDto clerkCustomer : clerkCustomerList) {
                Promotion promotion = new Promotion();

                // 收集会员编码
                custList.add(clerkCustomer.getCustNo());
                custMobile.put(clerkCustomer.getMobile(), clerkCustomer.getCustNo());
                // 会员编码做AES加密
                String aesCustNo = AESUtils.encrypt(clerkCustomer.getCustNo(), ConfigConstants.AES_KEY);
                promotion.setCustNo(aesCustNo);

                // 将未脱敏的手机号码存起来，下面查询首购复购时会根据手机号码查询,查询完成之后再对手机号进行脱敏
                promotion.setMobile(clerkCustomer.getMobile());
                // yy-dd
                promotion.setPromoteDate(DateUtils.getDateStrByFormat(clerkCustomer.getCreateTime(), "MM-dd"));
                if (SCAN_REG.equals(clerkCustomer.getChannel())) {
                    promotion.setPromotionSrcTxt("扫码注册");
                }
                if (VALET_REG.equals(clerkCustomer.getChannel())) {
                    promotion.setPromotionSrcTxt("代客注册");
                }
                if (DJ_APP_REG.equals(clerkCustomer.getChannel())) {
                    promotion.setPromotionSrcTxt("一键注册");
                }

                // 会员画像url
                String memberProtraitUrl = DJStringUtils.getMemberProtraitUrl(clerkCustomer.getCustNo());
                promotion.setMemberPortraitUrl(memberProtraitUrl);

                promotionList.add(promotion);
            }
        }

        // 批量查询会员购买次数,更新数据列表
        batchUpdatePromotionList(promotionList, custList, custMobile);

        // 如果是第一页过来的话，返回所有渠道来源和对应id
        if (currIndex == 0) {
            promotionSrcList = getSources(ClerkConstants.CLERKDEV_SOURCE_KEY);
        }

        // 返回给客户端发展概况文案
        MessageFormat form = new MessageFormat(ClerkConstants.CLERKDEV_TITLE_MSG);
        String promotionOverview = form.format(getTitleParam(promoteDate, staffId));

        promotionDetail.setPromotionSrcList(promotionSrcList);
        promotionDetail.setPromotionOverview(promotionOverview);
        promotionDetail.setPromotionList(promotionList);
        // 设置统计时间 会员发展是实时查询的,直接取昨天的日期
        Date yestday = DateUtils.getNextDay(new Date(), -1);
        String statisDate = DateUtils.getDateStrByFormat(yestday, DateUtils.DEFAULT_CHINA_DATE_PATTERN);
        promotionDetail.setStatisDate(statisDate);
        return promotionDetail;
    }

    /**
     * 更新数据列表首购复购信息
     * 
     * @param promotionList
     */
    private void batchUpdatePromotionList(List<Promotion> promotionList, List<String> custList,
            Map<String, String> custMobile) {
        Map<String, String> frequencyList = shopFrequencyService.queryShopFrequency(custList);

        for (Promotion promotion : promotionList) {
            String frequency = frequencyList.get(custMobile.get(promotion.getMobile()));

            // 查询会员首购复购接口
            CustshopFrequency custshopFrequency = DJStringUtils.getDealType(frequency);
            promotion.setDealTypeTxt(custshopFrequency.getDealTypeTxt());
            promotion.setDealType(custshopFrequency.getDealType());
            String mobile = "";
            String encryMobile = "";
            if (StringUtils.isNotBlank(promotion.getMobile())) {
                // 对手机号进行AES加密处理
                mobile = AESUtils.encrypt(promotion.getMobile(), ConfigConstants.AES_KEY);
                encryMobile = DJStringUtils.sensitiveHandleEx(promotion.getMobile(), 3, 2);
            }
            promotion.setMobile(mobile);
            promotion.setEncryMobile(encryMobile);
        }
    }

    /**
     * 获取会员发展详情标题参数
     * 
     * @param timeType
     * @param staffId
     * @return
     */
    private String[] getTitleParam(String timeType, String staffId) {
        // 默认的累计发展会员数
        String clerkDev = "0";
        String[] testArgs = new String[2];

        ClerkCustomerDevDataDto custDevDto = null;
        try {
            custDevDto = storeManRemoteService.getClerkCustomerDevData(staffId);
        } catch (Exception e) {
            LOGGER.error("会员发展列表统计会员发展详情发生异常，timeType=" + timeType + ",staffId=" + staffId + ",error=" + e);
        }
        if (null != custDevDto) {
            // 转换提成时间
            if (ClerkConstants.LASTMONTH_DEV.equals(timeType)) { // 上月提成
                testArgs[0] = "上月";
                clerkDev = String.valueOf(custDevDto.getLastMonthPromotion());
            } else if (ClerkConstants.YEASTERDAY_DEV.equals(timeType)) {
                testArgs[0] = "昨日";
                clerkDev = String.valueOf(custDevDto.getYesterdayPromotion());
            } else {
                testArgs[0] = "本月";
                clerkDev = String.valueOf(custDevDto.getCurMonthPromotion());
            }
        }
        testArgs[1] = clerkDev;
        return testArgs;
    }

    /**
     * 来源列表拼装 从配置库读配置 拼接组装成对象返回
     * 
     * @return
     */
    private List<PromotionSrc> getSources(String key) {
        LOGGER.debug("begin clerkDevSources ");
        List<PromotionSrc> list = new ArrayList<PromotionSrc>();
        String strs = ConfigUtil.getConfig(ConfigConstants.SAWP_CONFIG_PATH, key, "");

        // 为空或未配置,默认全部来源
        if (null == strs || "".equals(strs)) {
            PromotionSrc source = new PromotionSrc();
            source.setId("");
            source.setName("全部来源");
            list.add(source);
        } else {
            // 按照分号;区分来源类型,
            String[] sources = strs.split(";");
            PromotionSrc source;
            for (String sourceStr : sources) {
                source = getPromotionSrc(sourceStr);
                if (null != source) {
                    list.add(source);  
                }
            }
        }
        return list;
    }
    
    /**
     * 解析字符串
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param sourceStr
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private PromotionSrc getPromotionSrc(String sourceStr) {
        if (StringUtils.isNotBlank(sourceStr)) {
            // 按照减号-区分来源ID,NAME
            String[] attr = sourceStr.split("-");
            if (null != attr && attr.length == 2) {
                PromotionSrc source = new PromotionSrc();
                source.setId(attr[0]);
                source.setName(attr[1]);
                return source;
            }
        }
        return null;
    }

    @Override
    public List<OmsOrderItemPos> queryOmsOrderItemsCommission(String omsOrderNo, String dateFormat) {
        List<OmsOrderItemPos> result = null;
        String itemsJsonValue = cacheUtils.get(String.format(CacheKeyConstants.OMS_ORDER_COMMISSION, omsOrderNo));
        if (StringUtils.isNotBlank(itemsJsonValue)) {
            result = JSON.parseArray(itemsJsonValue, OmsOrderItemPos.class);
        } else {
            result = biDataDaoService.queryItemIncomeDetailByOrderNo(omsOrderNo, dateFormat);
            if (CollectionUtils.isEmpty(result)) {
                result = Lists.newArrayList();
            }
            // 数据库查询不到缓存空,防止无数据穿透缓存
            cacheUtils.setex(String.format(CacheKeyConstants.OMS_ORDER_COMMISSION, omsOrderNo),
                    CacheKeyConstants.COMMON_EXPIRE_TIME / 2, JSON.toJSONString(result));
        }
        return result;
    }

    @Override
    public StoreManDevMemberData queryPosDevMemberData(String staffId) {
        StoreManDevMemberData data = new StoreManDevMemberData();
        // 昨日发展会员
        int yesterdayPromotion = 0;
        // 本月发展会员
        int curMonthPromotion = 0;
        // 累计发展会员
        int promotionTotal = 0;
        // 店+渠道的会员发展情况
        ClerkCustomerDevDataDto devDto = storeManRemoteService.getClerkCustomerDevData(staffId);
        if (null != devDto) {
            yesterdayPromotion += devDto.getYesterdayPromotion();
            curMonthPromotion += devDto.getCurMonthPromotion();
            promotionTotal += devDto.getPromotionTotal();
        }
        // POS渠道会员发展情况
        Date yetd = DateUtils.getNextDay(new Date(), -1);
        String yetdStr = DateUtils.getDateStrByFormat(yetd, DateUtils.YYYYMMDD_PATTERN);
        // 取POS渠道 累计会员数、本月会员数、昨日会员数
        StoreManTotalDevMember totalDevMember = biDataDaoService.queryTotalMemberByStaffIdAndDate(staffId, yetdStr);
        if (null == totalDevMember) {
            // 如果昨天数据取不到，补偿下取前天数据
            Date beforeYetd = DateUtils.getNextDay(yetd, -1);
            String beforeYetdStr = DateUtils.getDateStrByFormat(beforeYetd, DateUtils.YYYYMMDD_PATTERN);
            totalDevMember = biDataDaoService.queryTotalMemberByStaffIdAndDate(staffId, beforeYetdStr);
        }
        if (null != totalDevMember) {
            yesterdayPromotion += (null != totalDevMember.getYtdPosRegMemberNum()
                    ? totalDevMember.getYtdPosRegMemberNum() : 0);
            curMonthPromotion += (null != totalDevMember.getMonPosRegMemberNum()
                    ? totalDevMember.getMonPosRegMemberNum() : 0);
            promotionTotal += (null != totalDevMember.getTotalPosRegMemberNum()
                    ? totalDevMember.getTotalPosRegMemberNum() : 0);
        }

        data.setCurMonthPromotion(curMonthPromotion);
        data.setPromotionTotal(promotionTotal);
        data.setYesterdayPromotion(yesterdayPromotion);

        return data;
    }

    @Override
    public ReturnMsg<PromotionDetail> queryPosPromotionList(String promoteDate, Integer startIndex, Integer limit,
            String staffId) {
        ReturnMsg<PromotionDetail> returnMsg = new ReturnMsg<PromotionDetail>();
        PromotionDetail promotionDetail = new PromotionDetail();
        // 默认按本月处理
        // 本月月头日期
        Date thisMonStartDate = DateUtils.getFirstDayZeroPointOfMonth(0);
        String startDateStr = DateUtils.getDateStrByFormat(thisMonStartDate, DateUtils.YYYYMMDD_PATTERN);
        Date nextMonStartDate = DateUtils.getFirstDayZeroPointOfMonth(1);
        String endDateStr = DateUtils.getDateStrByFormat(nextMonStartDate, DateUtils.YYYYMMDD_PATTERN);

        String topTip = "";
        String statisDate;
        if (ClerkConstants.LASTMONTH_DEV.equals(promoteDate)) {
            // 上月
            Date lastMonStartDate = DateUtils.getFirstDayZeroPointOfMonth(-1);
            startDateStr = DateUtils.getDateStrByFormat(lastMonStartDate, DateUtils.YYYYMMDD_PATTERN);
            endDateStr = DateUtils.getDateStrByFormat(thisMonStartDate, DateUtils.YYYYMMDD_PATTERN);
            // 上月统计日期截止于上月月末
            statisDate = DateUtils.getDateStrByFormat(DateUtils.getNextDay(thisMonStartDate, -1),
                    DateUtils.DEFAULT_CHINA_DATE_PATTERN);
        } else if (ClerkConstants.YEASTERDAY_DEV.equals(promoteDate)) {
            // 昨日
            Date yetd = DateUtils.getNextDay(new Date(), -1);
            Date today = new Date();
            startDateStr = DateUtils.getDateStrByFormat(yetd, DateUtils.YYYYMMDD_PATTERN);
            endDateStr = DateUtils.getDateStrByFormat(today, DateUtils.YYYYMMDD_PATTERN);
            // 截止日期
            statisDate = DateUtils.getDateStrByFormat(yetd, DateUtils.DEFAULT_CHINA_DATE_PATTERN);
        } else {
            // 本月统计截止日期到昨天
            statisDate = DateUtils.getDateStrByFormat(DateUtils.getNextDay(new Date(), -1),
                    DateUtils.DEFAULT_CHINA_DATE_PATTERN);
        }
        if (startIndex == 0) {
            // 如果是第一页，返回顶部文案提示
            // 查询选定时间段内发展会员总数
            int memberCount = biDataDaoService.countMemberInPriord(staffId, startDateStr, endDateStr);
            // 顶部文案
            topTip = getPosRegTitle(promoteDate, memberCount);
        }

        // 查询列表明细数据
        List<StoreManDevMemberDetail> members = biDataDaoService.queryMemberDetailList(staffId, startDateStr,
                endDateStr, startIndex, limit);
        List<String> custNos = new ArrayList<String>();
        for (StoreManDevMemberDetail detail : members) {
            custNos.add(detail.getMemberId());
        }
        // 取手机号
        Map<String, String> custMobiles = getMemberMobiles(custNos);
        // 取首复购标识
        Map<String, String> frequencyList = shopFrequencyService.queryShopFrequency(custNos);
        // 组装最终所需数据
        List<Promotion> promotionList = new ArrayList<Promotion>();
        for (StoreManDevMemberDetail detail : members) {
            Promotion promotion = new Promotion();
            // 加密会员编码
            String aesCustNo = AESUtils.encrypt(detail.getMemberId(), ConfigConstants.AES_KEY);
            promotion.setCustNo(aesCustNo);
            // 会员画像url
            String memberProtraitUrl = DJStringUtils.getMemberProtraitUrl(detail.getMemberId());
            promotion.setMemberPortraitUrl(memberProtraitUrl);
            // 发展会员日期
            String date = detail.getStatisDate().substring(4, 6) + "-" + detail.getStatisDate().substring(6, 8);
            promotion.setPromoteDate(date);
            // 取会员手机号
            String cmfMobile = custMobiles.get(detail.getMemberId());
            if (StringUtils.isNotBlank(cmfMobile)) {
                // 对手机号进行AES加密处理
                String mobile = AESUtils.encrypt(cmfMobile, ConfigConstants.AES_KEY);
                promotion.setMobile(mobile);
                // 脱敏手机号
                String encryMobile = DJStringUtils.sensitiveHandleEx(cmfMobile, 3, 2);
                promotion.setEncryMobile(encryMobile);
            }
            // 取首付购标识
            String frequency = frequencyList.get(detail.getMemberId());
            // 查询会员首购复购接口
            CustshopFrequency custshopFrequency = DJStringUtils.getDealType(frequency);
            promotion.setDealTypeTxt(custshopFrequency.getDealTypeTxt());
            promotion.setDealType(custshopFrequency.getDealType());

            // 加入到list
            promotionList.add(promotion);
        }

        promotionDetail.setPromotionList(promotionList);
        promotionDetail.setPromotionOverview(topTip);
        // 统计时间截止至
        promotionDetail.setStatisDate(statisDate);

        returnMsg.setData(promotionDetail);
        return returnMsg;
    }

    /**
     * 
     * 功能描述: 从会员中心取对应手机号<br>
     * 〈功能详细描述〉
     *
     * @param custNoList
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private Map<String, String> getMemberMobiles(List<String> custNoList) {
        Map<String, String> custMobiles = new HashMap<String, String>();
        QuerySocialityInfoResp infoResp = memberInfoService.querySocialityInfoAConstellation(custNoList);
        if (null != infoResp && null != infoResp.getBody() && CollectionUtils.isNotEmpty(infoResp.getBody().getCustSocietyInfoStructList())) {
            for (CustSocietyInfoStruct infoStruct : infoResp.getBody().getCustSocietyInfoStructList()) {
                if (CollectionUtils.isNotEmpty(infoStruct.getAccountAliasList())) {
                    String cmfMobile = getCmfMobile(infoStruct.getAccountAliasList());
                    custMobiles.put(infoStruct.getCustNum(), cmfMobile);
                }
            }
        }

        return custMobiles;
    }
    
    /**
     * 解析手机号
     * 功能描述: <br>
     * 〈功能详细描述〉
     *
     * @param list
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getCmfMobile(List<AccountAlias> list) {
        for (AccountAlias alias : list) {
            if (AccountAlias.AliasType.MOBILE.equals(alias.getAliasType())) {
                return alias.getAliasName();
            }
        }
        return null;
    }

    /**
     * 
     * 功能描述: 组装POS渠道发展会员顶部文案<br>
     * 〈功能详细描述〉
     *
     * @param timeType
     * @param clerkMemberCount
     * @return
     * @see [相关类/方法](可选)
     * @since [产品/模块版本](可选)
     */
    private String getPosRegTitle(String timeType, int clerkMemberCount) {
        // 默认的累计发展会员数
        String clerkDev = String.valueOf(clerkMemberCount);
        String[] testArgs = new String[2];

        // 转换提成时间
        if (ClerkConstants.LASTMONTH_DEV.equals(timeType)) { // 上月提成
            testArgs[0] = "上月";
        } else if (ClerkConstants.YEASTERDAY_DEV.equals(timeType)) {
            testArgs[0] = "昨日";
        } else {
            testArgs[0] = "本月";
        }
        testArgs[1] = clerkDev;

        MessageFormat form = new MessageFormat(ClerkConstants.POS_REGISTER_TITLE);
        return form.format(testArgs);
    }

    private static BigDecimal setScale2(BigDecimal decimal) {
        return (null == decimal ? new BigDecimal("0.0") : decimal).setScale(2, RoundingMode.FLOOR);
    }

    @Override
    public ReturnMsg<StoreManRealIncomeList> queryRealCommssionList(String staffId, Integer startIndex, Integer limit) {
        ReturnMsg<StoreManRealIncomeList> returnMsg = new ReturnMsg<StoreManRealIncomeList>();
        StoreManRealIncomeList incomeList = new StoreManRealIncomeList();
        // 提成只查询上月数据
        if (0 == startIndex) {
            // 第一页，返回文案描述
            StoreManRealIncSum entity = biDataDaoService.queryTotalIncomeInfo(staffId);
            // 默认取上月月份
            Date lastMonStartDate = DateUtils.getDateByStr(
                    ((null != entity && StringUtils.isNotBlank(entity.getIncMonth())) ? entity.getIncMonth() : DateUtils.getLastMonth()) + "01",
                    DateUtils.YYYYMMDD_PATTERN);
            String lastMon = String.valueOf(DateUtils.getMonOfDate(lastMonStartDate));
            if (null != entity) {
                // 提成
                String totIncome = setScale2(entity.getTotIncome()).toPlainString();
                Object orderTotNum = entity.getOrderTotNum();
                Object[] params = { lastMon, totIncome, orderTotNum };
                MessageFormat form = new MessageFormat(ClerkConstants.REAL_INCOME_TITLE_MSG);
                String desc = form.format(params);
                incomeList.setDesc(desc);
            }
            // 提成月份
            // 上月月初
            Date lastMonEndDate = DateUtils.getNextDay(DateUtils.getMonthEndDate(lastMonStartDate), -1);
            String lastMonStartDateStr = DateUtils.getDateStrByFormat(lastMonStartDate, "MM.dd");
            String lastMonEndDateStr = DateUtils.getDateStrByFormat(lastMonEndDate, "MM.dd");
            String[] tipParams = { lastMonStartDateStr, lastMonEndDateStr };
            MessageFormat format = new MessageFormat(ClerkConstants.BOTTOM_INCOME_TIP);
            String bottomTip = format.format(tipParams);
            incomeList.setBottomTip(bottomTip);

            // 提成月份
            incomeList.setMonth(lastMon);
        }
        // 查询列表
        List<BiStoreRealIncDetailMEntity> list = biDataDaoService.queryRealIncomeDetails(staffId, startIndex, limit);
        List<StoreManRealIncomeDetail> orderList = new ArrayList<StoreManRealIncomeDetail>();
        for (BiStoreRealIncDetailMEntity entity : list) {
            StoreManRealIncomeDetail detail = new StoreManRealIncomeDetail();
            detail.setGoodsCode(entity.getGdsCd());
            detail.setGoodsName(entity.getGdsNm());
            detail.setOrderItemNo(entity.getOmsOrderItemId());
            detail.setOrderNo(entity.getOmsOrderId());
            detail.setPosOrderItemNo(entity.getPosOrderItemId());
            detail.setOrderTime(DateUtils.getDateStrByFormat(entity.getOrderTime(), DateUtils.DEFAULT_TIME_PATTERN));
            detail.setPartnumberAmt(entity.getPartnumberAmt());
            detail.setPayAmt(entity.getPayAmt());

            orderList.add(detail);
        }
        incomeList.setOrderList(orderList);
        returnMsg.setData(incomeList);

        return returnMsg;
    }

}
